/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.deange.ropeprogress;

import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry;
import ohos.agp.window.service.Display;
import ohos.agp.window.service.DisplayManager;
import ohos.app.Context;
import org.junit.Test;

/**
 * com.deange.ropeprogress
 *
 * @author hw
 * @since 2021/6/1
 */
public class PixelUtilTest{
    Context context = AbilityDelegatorRegistry.getAbilityDelegator().getAppContext();
    Display display = DisplayManager.getInstance().getDefaultDisplay(context).get();

    @Test
    public void fp2px() {
        float fp = 10;
        float sca = display.getAttributes().scalDensity;
        int result = (int) (fp * sca + 0.5F * (fp >= 0 ? 1 : -1));
        System.out.println("fp2px result: " + result);
    }

    @Test
    public void vp2px() {
        float vp = 64;
        float dpi = display.getAttributes().densityPixels;
        float result = vp * dpi + 0.5F * (vp >= 0 ? 1 : -1);
        System.out.println("vp2px result: " + result);
    }
}